﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.pbcattblMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void pbcattbl_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            pbcattblMgr mgr = new pbcattblMgr();
            e.Total = int.Parse(mgr.GetRecordCount_pbcattbl(e.Parameters[pbcattbl_Filter.ParamPrefix]));
            IList<pbcattbl> list = mgr.FindAllByPage_pbcattbl(e.Start.ToString(), e.Limit.ToString(), e.Parameters[pbcattbl_Filter.ParamPrefix]);
            pbcattbl_MainStore.DataSource = list;
            pbcattbl_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            pbcattblMgr mgr = new pbcattblMgr();
            RowSelectionModel sm = pbcattbl_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                pbcattbl _pbcattbl = new pbcattbl();
                _pbcattbl.pbt_tnam = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_pbcattbl(_pbcattbl))
                {
                    log.Debug("pbcattbl中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            pbcattbl_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            pbcattblMgr mgr = new pbcattblMgr();
            pbcattbl _pbcattbl = new pbcattbl();
            if (Hid.Text.Length > 0)
                _pbcattbl = mgr.FindById_pbcattbl(int.Parse(Hid.Text));
            
			_pbcattbl.pbt_tid = int.Parse(TxtNumpbt_tid.Text.Trim());
			_pbcattbl.pbt_ownr = Txtpbt_ownr.Text.Trim();
			_pbcattbl.pbd_fhgt = Txtpbd_fhgt.Text.Trim();
			_pbcattbl.pbd_fwgt = Txtpbd_fwgt.Text.Trim();
			_pbcattbl.pbd_fitl = Txtpbd_fitl.Text.Trim();
			_pbcattbl.pbd_funl = Txtpbd_funl.Text.Trim();
			_pbcattbl.pbd_fchr = Txtpbd_fchr.Text.Trim();
			_pbcattbl.pbd_fptc = Txtpbd_fptc.Text.Trim();
			_pbcattbl.pbd_ffce = Txtpbd_ffce.Text.Trim();
			_pbcattbl.pbh_fhgt = Txtpbh_fhgt.Text.Trim();
			_pbcattbl.pbh_fwgt = Txtpbh_fwgt.Text.Trim();
			_pbcattbl.pbh_fitl = Txtpbh_fitl.Text.Trim();
			_pbcattbl.pbh_funl = Txtpbh_funl.Text.Trim();
			_pbcattbl.pbh_fchr = Txtpbh_fchr.Text.Trim();
			_pbcattbl.pbh_fptc = Txtpbh_fptc.Text.Trim();
			_pbcattbl.pbh_ffce = Txtpbh_ffce.Text.Trim();
			_pbcattbl.pbl_fhgt = Txtpbl_fhgt.Text.Trim();
			_pbcattbl.pbl_fwgt = Txtpbl_fwgt.Text.Trim();
			_pbcattbl.pbl_fitl = Txtpbl_fitl.Text.Trim();
			_pbcattbl.pbl_funl = Txtpbl_funl.Text.Trim();
			_pbcattbl.pbl_fchr = Txtpbl_fchr.Text.Trim();
			_pbcattbl.pbl_fptc = Txtpbl_fptc.Text.Trim();
			_pbcattbl.pbl_ffce = Txtpbl_ffce.Text.Trim();
			_pbcattbl.pbt_cmnt = Txtpbt_cmnt.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_pbcattbl(_pbcattbl);
            else
                isok = mgr.Add_pbcattbl(_pbcattbl);
            if (isok)
            {
                pbcattbl_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("pbcattbl中执行了保存（插入或修改），并成功");
                pbcattbl_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}